/*
 * 验证码检查
 */

package cn.edu.ntu.yyl.tool.code;

import org.springframework.stereotype.Controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
	public class Check extends HttpServlet {
		 private static final long serialVersionUID = 1L;
		 private boolean codeCheck = false;
		 public String code ;
		 public boolean getResult(){return codeCheck;}

			protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
			{
				doPost(request,response);
			}

			public void doPost(HttpServletRequest request, HttpServletResponse response)
					throws ServletException, IOException {
				code = request.getParameter("captcha");
				// 验证验证码
				String sessionCode = request.getSession().getAttribute("code").toString();
				if (code != null && !"".equals(code) && sessionCode != null && !"".equals(sessionCode))
				{
					if (code.equalsIgnoreCase(sessionCode)) {
						codeCheck = true;
					}
				}
				else {codeCheck = false;}
			}
	}
